require("../css/play.less");
const baseUrl = require("../utils/baseUrl.js");
const utils = require("../utils/utils.js");

window.onload = function () {
    let xia = document.querySelector("#xia");
    let shang = document.querySelector("#shang");
    let sho = document.querySelector("#sho");
    let video = document.querySelector("video");
    let title = document.querySelector(".con p");
    let mom = document.querySelector(".mom");

    let ship = JSON.parse(sessionStorage.getItem("ship"))
    let index = 0;

    function render() {
        video.src = baseUrl + ship[index].videoUrl;
        document.querySelector(".text1").innerText = index + 1;
        document.querySelector(".text2").innerText = ship.length;
        title.innerText = ship[index].title;
    }
    render();
    //下一下
    xia.addEventListener("click",function(){
        index++;
        if(index>ship.length-1){
            utils.toast(1,"已结束");
            index = ship.length-1;
        }
        render();
    })

    //上一个
    shang.addEventListener("click",function(){
        index--;
        if(index<0){
            index = 0;
        }
        render();
    })

    //自动播放下一个
    video.addEventListener("ended",function(){


        xia.click();
    })

    //进度条
    let jind = document.querySelector(".bom1");

    setInterval(function(){
        let w = video.currentTime /video.duration*100 +'%';
        jind.style.width = w;
    },100)

    //暂停
    sho.addEventListener("click",function(){
        mom.style.display = "block";
        video.pause();
        document.querySelector(".img img").src = baseUrl + ship[index].imgUrl;
        document.querySelector(".ship-item p").innerText = ship[index].title;

    })

    //继续播放
    let jix = document.querySelector(".momD-left");

    jix.addEventListener("click",function(){
        mom.style.display = "none";
        video.play();
    })

    //结束播放
    let jies = document.querySelector(".momD-right");

    jies.addEventListener("click",function(){
        // console.log("点你了");
        location.href = "../course.html";
        
    })

    //点击返回
    let fanh = document.querySelector(".sty");

    fanh.addEventListener("click",function(){
        history.back();
    })









}